//******************************************************************
//******************************************************************
//**********          ANts Peer To Peer Sources        *************
//
// ANts P2P realizes a third generation P2P net. It protects your
// privacy while you are connected and makes you not trackable, hiding
// your identity (ip) and crypting everything you are sending/receiving
// from others.

// Copyright (C) 2004  Roberto Rossi

// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

package ants.p2p.query;

import javax.crypto.*;

public class QuerySupernodeTuple extends QueryTuple {
  Object totalShareDimension;
  Object seenOn;
  Object ownerIP;
  Object queryMessage;
  Object id;

  public QuerySupernodeTuple(String sessionKey, Long seenOn, Long totalShareDimension, QueryMessage queryMessage, String id, String ip) {
    super(sessionKey);
    this.totalShareDimension = totalShareDimension;
    this.seenOn = seenOn;
    this.ownerIP=ip;
    this.queryMessage = queryMessage;
    this.id = id;
  }

  public String getEncryptedSessionKey(){
    return this.sessionKey;
  }

  public String getOwnerID(){
    if (this.id instanceof String)
      return (String)this.id;
    else
      return null;
  }

  public String getOwnerIP() {
    if (this.ownerIP instanceof String)
      return (String)this.ownerIP;
    else
      return null;
  }

  public Long getTotalShareDimension(){
    if (this.totalShareDimension instanceof Long)
      return (Long)this.totalShareDimension;
    else
      return null;
  }

  public Long getSeenOn(){
    if (this.seenOn instanceof Long)
      return (Long)this.seenOn;
    else
      return null;
  }

  public QueryMessage getQueryMessage(){
    if (this.queryMessage instanceof QueryMessage)
      return (QueryMessage)this.queryMessage;
    else
      return null;
  }

  public void encrypt(Cipher c) throws Exception {
    this.totalShareDimension = new SealedObject((Long)this.totalShareDimension, c);
    //this.seenOn = new SealedObject((Long)this.seenOn, c);
    this.queryMessage = new SealedObject((QueryMessage)this.queryMessage, c);
    //this.id = new SealedObject((String)this.id, c);
  }

  public void decrypt(Cipher c) throws Exception {
    this.totalShareDimension = (Long)((SealedObject)this.totalShareDimension).getObject(c);
    //this.seenOn = (Long)((SealedObject)this.seenOn).getObject(c);
    this.queryMessage = (QueryMessage)((SealedObject)this.queryMessage).getObject(c);
    //this.id = (String)((SealedObject)this.id).getObject(c);
  }
}
